package com.alipay.app.groupmeal.standard.mqtt;

import com.tencent.iot.explorer.device.java.data_template.TXDataTemplateDownStreamCallBack;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 实现下行消息处理的回调接口
 */
public class SelfDownStreamCallBack extends TXDataTemplateDownStreamCallBack {
    @Override
    public void onReplyCallBack(String replyMsg) {
        //可根据自己需求进行处理属性上报以及事件的回复，根据需求填写
//            Log.d(TAG, "reply received : " + replyMsg);
    }

    @Override
    public void onGetStatusReplyCallBack(JSONObject data) {
        //可根据自己需求进行处理状态和控制信息的获取结果
//            Log.d(TAG, "event down stream message received : " + data);
    }

    @Override
    public JSONObject onControlCallBack(JSONObject msg) {
//            Log.d(TAG, "control down stream message received : " + msg);
        //do something

        //output
        try {
            JSONObject result = new JSONObject();
            result.put("code", 0);
            result.put("status", "some message wher errorsome message when error");
            return result;
        } catch (JSONException e) {
//                mParent.printLogInfo(TAG, "Construct params failed!", mLogInfoText, TXLog.LEVEL_ERROR);
            return null;
        }
    }

    @Override
    public JSONObject onActionCallBack(String actionId, JSONObject params) {
//            TXLog.d(TAG, "action [%s] received, input:" + params, actionId);
        //do something based action id and input
        if (actionId.equals("blink")) {
//                try {
//                    Iterator<String> it = params.keys();
//                    while (it.hasNext()) {
//                        String key = it.next();
//                        TXLog.d(TAG, "Input parameter[%s]:" + params.get(key), key);
//                    }
//                    //construct result
//                    JSONObject result = new JSONObject();
//                    result.put("code", 0);
//                    result.put("status", "some message wher errorsome message when error");
//
//                    // response based on output
//                    JSONObject response = new JSONObject();
//                    response.put("result", 0);
//
//                    result.put("response", response);
//                    return result;
//                } catch (JSONException e) {
//                    mParent.printLogInfo(TAG, "Construct params failed!", mLogInfoText, TXLog.LEVEL_ERROR);
//                    return null;
//                }
        } else if (actionId.equals("YOUR ACTION")) {
            //do your action
        }
        return null;
    }

    @Override
    public void onUnbindDeviceCallBack(String msg) {
        //用户删除设备的通知消息
//            Log.d(TAG, "unbind device received : " + msg);
    }

    @Override
    public void onBindDeviceCallBack(String msg) {
        //用户绑定设备的通知消息
//            Log.d(TAG, "bind device received : " + msg);
    }
}
